package com.woniu.adopt.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.adopt.entity.Pet;
import com.woniu.adopt.entity.RescueStation;
import com.woniu.adopt.mapper.PetMapper;
import com.woniu.adopt.mapper.RescueStationMapper;
import com.woniu.adopt.vo.EchartsVo;
import com.woniu.adopt.vo.PetVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetService {
    @Autowired
    private PetMapper petMapper;

    @Autowired
    private RescueStationMapper rescueStationMapper;

    public PageInfo<PetVo> queryByPage(Integer now, Integer size, String name) {
        PageHelper.startPage(now, size);
        List<PetVo> pets = petMapper.selectAll(name);
        return new PageInfo<>(pets);
    }

    public PetVo queryPetByKey(Integer id) {
        return petMapper.selectByPrimaryKey(id);
    }

    public int add(Pet pet) {
        return petMapper.insert(pet);
    }

    public int removeByKey(Integer id) {

        return petMapper.deleteByPrimaryKey(id);
    }

    public int modify(PetVo pet) {
        return petMapper.updateByPrimaryKey(pet);
    }

    public List<RescueStation> queryAllRescueStation() {
        return rescueStationMapper.selectAll();
    }

    public List<EchartsVo> queryViews() {
        return petMapper.selectByViews();
    }
}
